<?php 
/*$section->appendSystemModule('right_sidebar', array('name'=>'events.eventInterested'));
// append map on sidebar
$section->appendSystemModule('right_sidebar', array('name'=>'cms.html','params' => array('html_content' => $this->element("event_view_map",array('showStreetView'=>true)))));*/
?>
<?php 
uses("Flay");
?>
<section class="hauptseite events_detail">
	<div class="container">
		<div class="row">
			<div class="row_detail">
				<div class="col-md-8 col_left">
					<div class="bg_black">
						<div class="each_line images_section">
							<?php
							$img = $html->image($event['Event']['image'],array('thumb'=>array('crop'=>true,'width'=>630,'height'=>283),'class'=>'thumbnail','alt'=>sprintf(__("%s picture"),$event['Event']['title'])));
							echo $html->link($img, array('plugin'=>'events',"controller"=>"event_assets",'action'=>'index','event','eventId'=>$event['Event']['id']),array('escape'=>false));
							?>
						</div>
						<!--images_section-->
						
						<div class="each_line padd">
							<h2 class="h2_title_detail"><?php echo $event['Event']['title']?></h2>
							<div class="event_content">
								<div class="row"> <strong><?php echo __('Category');?></strong>
									<div class="value"><?php echo $html->link($event['EventCategory']['name'], array('plugin'=>'events', 'controller' => 'events', 'action' => 'index', 'categoryId'=>$event['EventCategory']['id'], 'eventDate'=>null)); ?></div>
								</div>
								<div class="row"> <strong><?php echo __('When');?></strong>
									<div class="value"> 
										<?php
										$eventWhen = date("l, F, d h:i a",strtotime($event['Event']['event_from']));
										if(isset($event['Event']['event_to']) && $event['Event']['event_to']!=null)
										{
											$eventWhen = $eventWhen . ' - <BR/>' . date("l, F, d h:i a",strtotime($event['Event']['event_to']));
										}
										echo $eventWhen;
										
										$tmpStartDate = date("Ymd\THis\Z",strtotime($event['Event']['event_from']));
										$tmpEndDate = date("Ymd\THis\Z",strtotime($event['Event']['event_to']));
										$addToCalDate = $tmpStartDate . "/" . $tmpEndDate;
										
										$partialDescription = strip_tags($event['Event']['description']);
										$partialDescription = str_replace(array("\n"), "", $partialDescription);
										$flayTextLimit = cr("EventConfig.flay_text");
										if($flayTextLimit && strlen($partialDescription) > $flayTextLimit)
										{
											$partialDescription = Flay::fragment($partialDescription,$flayTextLimit);
										}
										echo "<br/>";
										echo "<a href=\"http://www.google.com/calendar/event?action=TEMPLATE&text=".$event['Event']['title']."&dates=".$addToCalDate."&details=".$partialDescription."&location=".$event['Event']['venue']."&trp=false&sprop=".$html->url($event['Event']['viewUrl'], true)."\" target=\"_blank\">".__("Add to Google Calendar")."</a>";
										echo "<br/>";
										
										echo $html->link(__('Add to Outlook Calendar', true), array("plugin"=>"events",'controller'=>'events','action'=>'generate_cal_file',$event['Event']['id']));
										?>
									</div>
								</div>
								<div class="row"> <strong><?php echo __('Venue'); ?></strong>
									<div class="value"><?php echo $event['Event']['venue']; ?></div>
								</div>
								<div class="row"> <strong><?php echo __('Cost'); ?></strong>
									<div class="value">
										<?php
										if(isset($event['Event']['event_cost']) && $event['Event']['event_cost']>0) 
										{
											echo "$ ".$event['Event']['event_cost'];
											if (isset($event['Event']['event_cost_to']) && $event['Event']['event_cost_to']>0)
											{
												echo " ".__("to")." $ ".$event['Event']['event_cost_to'];
											}
										} else {
											echo __("Free");
										}
										?>
									</div>
								</div>
								<div class="row"> <strong><?php echo __('How');?></strong>
									<div class="value">
										<?php 
										if ($event['Event']['event_site'] !=="") 
										{
											if(substr($event['Event']['event_site'], 0,7) === "http://" || substr($event['Event']['event_site'], 0,6) === "https:") { 
												$url = $event['Event']['event_site'];  
											} else { 
												$url = "http://".$event['Event']['event_site'];
											}
											echo $html->link($event['Event']['event_site'],$url, array('target' => '_blank'));
											echo "<br/>";
										}
										if ($event['Event']['ticket_site'] !=="") 
										{
											if(substr($event['Event']['ticket_site'], 0, 7) === "http://" || substr($event['Event']['ticket_site'], 0, 6) === "https:") {
												$url = $event['Event']['ticket_site'];
											} else {
												$url = "http://".$event['Event']['ticket_site'];
											}
											echo $html->link($event['Event']['ticket_site'],$url, array('target' => '_blank'));
										}
										?>
									</div>
								</div>
								<?php if(isset($event['Event']['listing_id']) && !is_null($event['Event']['listing_id']) && $event['Event']['listing_id']) {?>
								<div class="row"> <strong><?php echo __('Business'); ?></strong>
									<div class="value"> 
										<?php echo $html->link($listing['Listing']['title'],$html->url($listing['Listing']['viewUrl'], true)); ?>
										<div>
											<?php 
											$_userReviewCount = '<div style="float:left;margin-left:80px">('.$listing['Listing']['review_count'].')</div>';
											$_userRating = $listing['Listing']['userAvg'];
											echo $rating->display(array('rating'=>$_userRating,'before_text'=>$_userReviewCount,'tooltip'=>__('User Rating').' '.number_format($_userRating,1),'tooltipClass'=>'user_'.$listing['Listing']['id'].'_'.mt_rand(1,1000)));
											if(cr('GeneralConfig.disable_editor_reviews') != 1)
											{
												$_editorRating = $listing['Listing']['editorialAvg'];
												echo $rating->display(array('rating'=>$_editorRating,'class'=>'editor_rating_star_value', 'parent_class'=>'editor_rating_star_base', 'tooltip'=>__('Editor Rating').' '.number_format($_editorRating,1),'tooltipClass'=>'editor_'.$listing['Listing']['id'].'_'.mt_rand(1,1000)));
											}
											?>
										</div>
									</div>
								</div>
								<?php }?>
								<div class="row"> <strong><?php echo __('Submitted By');?></strong>
									<div class="value">
										<?php
										if(isset($event['Event']['user_id']) && isset($event['User']))
										{
											echo $html->link($html->image($event['User']['avatar'],array('class'=>"profile_pic",'alt'=>sprintf(__("%s profile"),$event['User']['username']),'thumb'=>array('crop'=>true,'width'=>40,'height'=>40))),$event['User']['profile_url'],array("escape"=>false));
											echo "&nbsp;&nbsp;&nbsp;".$html->link($event['User']['display_name'], $event['User']['profile_url']);
										}
										else
										{
											echo __("Admin");
										}
										?>
									</div>
								</div>
								
								<?php if ($loggedInUser) { ?>
								<div class="actions">
											<?php 
								echo "<h4>".__("Are You Interested ?")."</h4>";
								if($isLoggedInUserAttending==0 && $isLoggedInUserInterested==0) 
								{
									echo $html->link(__("I'm in", true), array('controller'=>'events','action'=>'add_attendee',$event['Event']['id']),array('class'=>'button button_small')).' | ';
									echo $html->link(__("Sounds Cool", true), array('plugin'=>'events','controller'=>'events','action'=>'add_soundscool',$event['Event']['id']),array('class'=>'button button_small'));
								} else {
									if($isLoggedInUserAttending) 
									{
										echo __("You Replied").": <strong>".__("I'm in!")."</strong> ";
										echo $html->link(__("Cancel", true), array('plugin'=>'events','controller'=>'events','action'=>'revoke_attendee',$event['Event']['id']));
									}
									if($isLoggedInUserInterested) 
									{
										echo __("You Replied").": <strong>".__("Sounds Cool!")."</strong> ";
										echo $html->link(__("Cancel", true), array('plugin'=>'events','controller'=>'events','action'=>'revoke_soundscool',$event['Event']['id']));
									}
								}
								echo "<div class='clear'></div>";
								?>
								</div>
								<?php } ?>
							</div>
							<!--event_content-->
							<?php if ($event['Event']['description'] != ""){ ?>
								<hr>
								<strong><?php echo __('What/Why'); ?></strong><br/>
								<?php echo $event['Event']['description']; ?>
								<?php if((isset($showEditLink) || isset($showDeleteLink)) && ($showEditLink==true || $showDeleteLink==true)){ ?>
								<center>
									<?php 
										if(isset($showEditLink) && ($showEditLink==true)){
											echo "";
											echo "<div class='fr'>".$html->link(__('Edit', true), array("plugin"=>"events",'controller'=>'events','action'=>'edit',$event['Event']['slug']))."</div>";
											echo "";
										}
									?>
								</center>
								<center>
									<?php 
										if(isset($showDeleteLink) && ($showDeleteLink==true)){
											echo "<div class='fr'>|</div>";
											echo "<div class='fr'>".$html->link(__('Delete', true), array("plugin"=>"events",'controller'=>'events','action'=>'delete',$event['Event']['id']),null,sprintf(__('Are you sure you want to delete # %s?', true), $event['Event']['title']))."</div>";
											echo "";
										}
									?>
								</center>
								<hr>
								<?php } 
									}
								?>
							</div>
						<!--padd -->
						
						<div id="event_comments" class="related related_comments">
							<h3><?php echo __('Discuss This Event');?></h3>
							<?php
						if(!empty($comments))
						{
							echo "";
							foreach ($comments as $comment)
							{
								echo "<div class='comment_box altrow '>";
								echo "<div class='post_info fl'>";
								if(isset($comment['User']))
								{
									echo $html->link($html->image($comment['User']['avatar'],array('class'=>"profile_pic",'alt'=>sprintf(__("%s profile"),$comment['User']['display_name']),'thumb'=>array('crop'=>true,'width'=>40,'height'=>40))),$comment['User']['profile_url'],array("escape"=>false));
									echo " ";
									echo $html->link($comment['User']['display_name'],$comment['User']['profile_url']).__(" ");					
								}
								else
								{
									//echo __("Admin");
								}
								echo " ";
								echo "</div><div class='comment_body fl'>";
								echo "<div class='time'>";	
								echo $time->timeAgoInWords($comment['EventComment']['created'],array('shortString'=>true));
								echo "</div>";	
								echo "<div class='clear'></div>";
								echo $comment['EventComment']['description']."<br/>";
								echo "<br/>";
								if ($session->check('Auth.User.id'))
								{
									if ($session->read('Auth.User.id') == $comment['User']['id'])
									{
										echo $html->link(__('Delete'),array('plugin'=>'events','controller'=>'events','action'=>'delete_comment',$comment['EventComment']['id']));
									}
								}
								echo "</div><div class='clear'></div></div><div class='clear'></div>";					
							}
							echo "<br/>";
						
						}
						else
						{
							echo __("No one has commented on this event yet.");
						}
						?>
						<?php
						if(!empty($loggedInUser)) 
						{	
							echo " <label>".__("Enter Your Reply")."</label>";
							echo $form->create(array('type'=>'POST','action'=>'add_comment'));
							echo $form->textarea('comment', array('style'=>'width:570px;height:100px;'));
							echo $form->hidden('eventId',array('value'=>$event['Event']['id']));
							//echo $form->end(__('Add Comment'),array('div'=>array('class'=>'alignRight')));
							echo $form->end(array('label'=>__('Add Comment'), 'class'=>'bt_submit'));
						}
						?>
						</div>
						<!--related--> 
						
					</div>
					<!--bg_black--> 
				</div>
				<!--col_left-->
				
				<div class="col-md-4 col_right">
					<div class="col-md-12 map_view">
						<div class="wrap_iframe_map">
						<?php echo $this->element('event_view_map');?>
						</div>
					</div>
					<div id="event_sideblock" class="bg_black padd whos_in">
					<?php echo $this->element('whosin');?>
					</div>
					<!--bg_black--> 
				</div>
				<!--col_right--> 
				
			</div>
			<!--/.row_detail --> 
		</div>
		<!--/.row--> 
	</div>
	<!--/.container--> 
</section>
<!-- /.hauptseite-->
<script>
function doIt(){
	var eventId = <?php echo $event['Event']['id'];?>;
	var comment = document.getElementById('EventCommentEventComments').value;
	var url = "<?php echo $html->url(array('action'=>'add_comment'))?>";		
	url += '/eventId:'+eventId+'/comment:'+comment;
	return url;
}
</script>